
<!DOCTYPE html>
<html>
<head>[#include "../manage/common/head.html" /]
</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>客户信息</h5>
					</div>
					<div class="ibox-content">
						<table
							class="table table-striped table-bordered table-hover dataTables">
							<thead>
								<tr>
									<th class="text-center">用户名</th>
									<th class="text-center">登陆密码</th>
									<th class="text-center">昵称</th>
									<th class="text-center">用户唯一标识</th>
									<th class="text-center">会话密钥</th>
									<th class="text-center">用户状态</th>
									<th class="text-center">最后访问时间</th>
									<th class="text-center">注册时间</th>
									<th class="text-center">操作项</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>

					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="windowModal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">新建</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="myForm">
						<div class="form-group">
							<label class="col-sm-2 control-label">是否锁定</label>
							<div class="col-sm-8">
								<select id="stateId"
										class="selectpicker show-tick form-control"
										data-live-search="false">
										<option value=""></option>
										<option value="1">有效</option>
										<option value="2">无效</option>
								</select>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer clearfix">
					<div class="form-group col-md-8 col-sm-offset-2 text-center">
						<button type="button" class="btn btn-primary" id="save">保存</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	[#include "../manage/common/js.html" /]
	<script>
		function restForm() {
			$("#stateId").val("");
		}

		$("#windowModal").on("hidden.bs.modal", function() {
			restForm();
		});

		var oid = 0;
		$('#windowModal').on(
				'show.bs.modal',
				function(event) {
					var button = $(event.relatedTarget);
					var recipient = button.data('title');
					var modal = $(this);
					modal.find('.modal-title').text(recipient);
					if (recipient == "编辑") {
						$.post("${base}/manage/user/getUser/" + button.data('id'), function(r) {
							oid = r.userDate.id;
						}, 'json')
					} else {
						oid = 0;
					}
				});

		$(function() {
			dt = $('.dataTables').dataTable({
				"ordering" : false,
				"searching" : false,
				"info" : true,
				"bLengthChange" : false,
				"pagingType" : "full_numbers",
				"language" : {
					"lengthMenu" : "每页 _MENU_ 条记录",
					"zeroRecords" : "没有找到记录",
					"info" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
					"infoEmpty" : "无记录",
					"infoFiltered" : "(从 _MAX_ 条记录过滤)",
					"sEmptyTable" : "表中数据为空",
					"sLoadingRecords" : "载入中...",
					"oPaginate" : {
						"sFirst" : "首页",
						"sPrevious" : "上一页",
						"sNext" : "下一页",
						"sLast" : "末页"
					}
				},
				"serverSide" : true,
				"sAjaxSource" : "${base}/manage/user/selectUserList",
				"columns" : [{
					"data" : "userName",
					"sWidth": "10%"
				},{
					"data" : "password",
					"sWidth": "10%"
				},{
					"data" : "nickName",
					"sWidth": "10%"
				},{
					"data" : "openid",
					"sWidth": "15%"
				},{
					"data" : "sessionKey",
					"sWidth": "15%"
				},{
					"data" : "state",
					"sWidth": "10%",
					"render" : function(data) {
						if(data == 1){
							return '有效'
						}else if(data == 2){
							return '无效'
						} else return "";
					}
				},{
					"data" : "lastVisitTime",
					"sWidth": "10%",
					"render" : function(data) {
						if(data != "" && data != null){
							return data.substr(0,10);
						} else return "";
					}
				},{
					"data" : "registerTime",
					"sWidth": "10%",
					"render" : function(data) {
						if(data != "" && data != null){
							return data.substr(0,10);
						} else return "";
					}
				}, {
					"data" : "id",
					"sWidth": "10%",
					"render" : function(data) {
						return '<div class="text-center"><button class="btn btn-info btn-sm" type="button" data-title="编辑" data-toggle="modal" data-target="#windowModal" data-id="'+ data+'" onclick="edit('+ data+')">编辑</button>'+
						'</div>';
					}
				}  ],
				"fnServerData" : function(sSource, aoData, fnCallback) {
					$.ajax({
						"dataType" : 'json',
						"type" : "POST",
						"url" : sSource,
						"data" : aoData,
						"success" : fnCallback
					});
				}
			});

		})

		function search() {
			dt.fnFilter();
		}

		$("#save").click(function() {
			var state = $("#stateId").val();
        	if(state == ""){
        		swal("警告","是否无效不能为空！","warning");
        		return;
        	}
			$.post("${base}/manage/user/save", {
				id : oid,
				state : state
			}, function(r) {
				if (r.code == 0) {
					swal("成功", "保存完成！", "success");
					$('#windowModal').modal('hide');
					search();
				} else {
					swal("错误", r.msg, "error");
				}
			}, 'json')
		})

		function edit(id) {
			$.post("${base}/manage/user/getUser/" + id, function(r) {
				$("#stateId").val(r.userDate.state);
				oid = id;
			}, 'json')

		}
		
	</script>
</body>
</html>
